package com.gjintel.auction.business.controller;/** * Created by Administrator on 2017/12/5 0005. */import com.gjintel.auction.business.model.AuctionCompareBid;import com.gjintel.auction.business.model.AuctionInfo;import com.gjintel.auction.business.service.IAuctionBidService;import com.gjintel.auction.business.service.IAuctionCompareBidService;import com.gjintel.auction.business.service.IAuctionService;import com.gjintel.auction.business.service.IEntryService;import com.gjintel.business.proj.model.ComposeIdPK;import com.gjintel.business.proj.model.ComposeIdPK2;import com.gjintel.business.proj.model.DepositReturn;import com.gjintel.business.proj.model.DepositReturnOut;import com.gjintel.business.proj.service.IDepositReturnService;import com.gjintel.business.proj.service.IProjectInfoService;import com.gjintel.business.proj.service.impl.NotifyServiceImpl;import com.gjintel.business.webcontent.model.WebContent;import com.gjintel.business.webcontent.service.IWebContentService;import com.gjintel.framework.common.service.IDepositExecuteService;import com.gjintel.framework.common.service.IDepositService;import com.gjintel.framework.constant.ActivitiMap;import com.gjintel.framework.constant.Constant;import com.gjintel.framework.constant.ProjectStatusAuction;import com.gjintel.framework.dataset.model.DataSet;import com.gjintel.framework.dataset.service.IDataSetService;import com.gjintel.framework.holidayset.service.IHolidaySetService;import com.gjintel.framework.register.model.RegisterUser;import com.gjintel.framework.register.service.IRegisterUserService;import com.gjintel.framework.res.model.Resources;import com.gjintel.framework.res.service.IResService;import com.gjintel.framework.user.model.User;import com.gjintel.framework.user.service.IUserService;import com.gjintel.framework.util.CommUtil;import com.gjintel.framework.util.FileResUtil;import com.gjintel.framework.util.dto.Bank;import com.gjintel.sdk.base.dao.Page;import com.gjintel.sdk.util.DateUtils;import com.gjintel.sdk.util.FileDownload;import com.gjintel.sdk.util.StringUtil;import com.gjintel.sdk.util.WordHandler;import com.gjintel.workflow.trade.service.IExecutionService;import com.gjintel.workflow.trade.service.IWorkflowProcessInstanceService;import net.sf.json.JSONObject;import org.activiti.engine.RuntimeService;import org.activiti.engine.TaskService;import org.activiti.engine.task.Task;import org.apache.commons.io.FileUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.HttpRequest;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.servlet.ModelAndView;import javax.annotation.Resource;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import javax.transaction.Transactional;import java.io.File;import java.io.IOException;import java.math.BigDecimal;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.*;import java.util.concurrent.*;/** * 采购项目Controller * * @author xuyefei */@RequestMapping("/auctionBid/business")@Controllerpublic class AuctionBidController {    @Resource    private IAuctionService auctionService;    @Autowired    private IEntryService entryService;    @Autowired    private IAuctionCompareBidService auctionCompareBidService;    @Autowired    private RuntimeService runtimeService;    @Autowired    private TaskService taskService;    @Autowired    private IWebContentService webContentService;    @Autowired    private IProjectInfoService projectInfoService;    @Autowired    private IWorkflowProcessInstanceService workflowProcessInstanceService;    @Autowired    private IUserService userService;    @Autowired    private IResService resService;    @Autowired    private IExecutionService executionService;    @Autowired    private IHolidaySetService holidaySetService;    @Autowired    private IDataSetService dataSetService;    @Autowired    private IDepositService depositService;    @Autowired    private IDepositReturnService depositReturnService;    @Autowired    private IRegisterUserService registerUserService;    @Autowired    private IAuctionBidService auctionBidService;    @Autowired    private IDepositExecuteService depositExecuteService;    @Autowired    private IDepositExecuteService executeDepositService;    @Autowired    private NotifyServiceImpl notifyService;    /**     * @param     * @return     * @description 竞拍人项目列表     */    @RequestMapping("/auction")    public ModelAndView aution(String code, HttpSession session) {        ModelAndView mv = new ModelAndView("/auction/business/auction");        User user = (User) session.getAttribute("loginUser");        AuctionInfo auctionInfo = auctionService.findByCode(code);        List<AuctionCompareBid> auctionCompareBidList = auctionCompareBidService.findTopTenByAuctionId(auctionInfo.getId());        List<AuctionCompareBid> myAuctionCompareBidList = auctionCompareBidService.findAllByAuctionIdAndBiddrId(auctionInfo.getId(), user.getId());        Integer auctionSleep = dataSetService.getDataSet().getAuctionSleep();        mv.addObject("auctionSleep", auctionSleep);        mv.addObject("auctionInfo", auctionInfo);        mv.addObject("auctionCompareBidList", auctionCompareBidList);        mv.addObject("auctionCompareBidListCount", auctionCompareBidService.countAllByAuctionId(auctionInfo.getId()));        mv.addObject("myAuctionCompareBidList", myAuctionCompareBidList);        return mv;    }    /**     * @param     * @return     * @description 获取服务器时间戳     */    @ResponseBody    @RequestMapping(value = "/getNowTime", method = RequestMethod.POST)    public long getNowTime() {        return System.currentTimeMillis();    }    /**     * @param     * @return     * @description 判断是否已经通过报名和已交保证金     */    @ResponseBody    @RequestMapping(value = "/getEntryAbleAndDeposit", method = RequestMethod.POST)    public JSONObject getEntryAbleAndDeposit(String code, HttpSession session) {        User user = (User) session.getAttribute("loginUser");        AuctionInfo auctionInfo = auctionService.findByCode(code);        boolean isEntryAble = true;        //判断是否需要报名        if (auctionInfo.getEntryAble() == true) {            isEntryAble = entryService.getEntryAble(auctionInfo.getId(), user.getId());//获取是否已经报名,且已经通过        }        RegisterUser registerUser = this.auctionService.get(RegisterUser.class, user.getRegisterId());        JSONObject json = new JSONObject();        json.put("userFlag", user.getFlag());        if (registerUser.getForbidEndDate() != null) {            json.put("forbidEndDate", registerUser.getForbidEndDate().getTime());        } else {            json.put("forbidEndDate", 0);        }        json.put("isEntryAble", isEntryAble);        if (isEntryAble == false) {            //如果报名信息 没有通过 就不需要实时校验保证金了 增加响应速度            json.put("depositStatus", -1);//是否已经交了保证金        } else {            //json.put("depositStatus", 1);            json.put("depositStatus", checkDeposit(user, auctionInfo));//是否已经交了保证金        }        return json;    }    /**     * @param     * @return     * @description 获取项目的开始竞拍时间和截止竞拍时间     */    @ResponseBody    @RequestMapping(value = "/getAuctionStartTimeAndEndTime", method = RequestMethod.POST)    public JSONObject getAuctionStartTimeAndEndTime(String code, HttpSession session) {        AuctionInfo auctionInfo = auctionService.findByCode(code);        JSONObject json = new JSONObject();        json.put("startTime", auctionInfo.getAuctionStart().getTime());        json.put("endTime", auctionInfo.getAuctionEnd().getTime());        return json;    }    /**     * @param     * @return     * @description 获取竞价的拟定中标人     */    @ResponseBody    @RequestMapping(value = "/getProposedAuctionWinner", method = RequestMethod.POST)    public JSONObject getProposedAuctionWinner(String code) {        try {            AuctionInfo auctionInfo = auctionService.findByCode(code);            AuctionCompareBid auctionCompareBid = auctionCompareBidService.findTopOneByAuctionId(auctionInfo.getId());            if (auctionCompareBid == null) {                return new JSONObject();            }            return JSONObject.fromObject(auctionCompareBid);        } catch (Exception ex) {            ex.printStackTrace();            return new JSONObject();        }    }    //校验保证金  保证金为0，不需要缴纳//已交为1,未交为0,错误  为 -1    private int checkDeposit(User user, AuctionInfo auctionInfo) {        //判断是否需要缴纳保证金        if (auctionInfo.getDeposit() > 0) {            RegisterUser registerUser = this.auctionService.get(RegisterUser.class, user.getRegisterId());            if (registerUser == null) {                return -1;            }            // 判断是否缴纳单项保证金            int ifPaySingleDeposit = depositService.ifPaySingleDeposit(registerUser.getId(), auctionInfo.getId(), registerUser.getLoginName(), auctionInfo.getAuctionName());            return ifPaySingleDeposit;        }        return 1;    }    /**     * 校验中标人履约保证金是否缴纳     *     * @return     */    @RequestMapping("/validBidBond")    @ResponseBody    public Boolean validBidBond(String auctionInfoId) {        AuctionInfo auctionInfo = auctionService.get(AuctionInfo.class, auctionInfoId);        if (auctionInfo.getTrusteeship() == false) {            //中心不托管 则不校验            return true;        }        if (auctionInfo.getExecuteDeposit() <= 0) {            //履约保证金为0则不校验            return true;        }        boolean reslut = isPayDepositReturn(auctionInfo);        return reslut;    }    //通过流程ID获取公告内容    private WebContent getWebContent(String id) {        String webId = (String) runtimeService.getVariable(id, "documentId");        return this.webContentService.get(WebContent.class, webId);    }    /**     * @param projectId     * @return     * @description 预览公告页面     * @author wwang     * @date 2017-12-05 16:29:13     */    @RequestMapping("/owner/previewWinnerNotice")    @ResponseBody    public ModelAndView previewWinnerNotice(String projectId) {        ModelAndView mv = new ModelAndView("/auction/owner/notifyResult");        AuctionInfo auctionInfo = auctionService.get(AuctionInfo.class, projectId);        Task task = workflowProcessInstanceService.findTask(auctionInfo.getWorkflowId());        WebContent webcontent = getWebContent(task.getProcessInstanceId());        mv.addObject("webcontent", webcontent);        return mv;    }    /**     * @description 产权人 确认结果页面     * @author shy     */    @RequestMapping("/owner/confirmResult")    public ModelAndView confirmResult(HttpSession session, String projectId) {        AuctionInfo auctionInfo = auctionService.get(AuctionInfo.class, projectId);        ModelAndView mv = new ModelAndView("/auction/owner/projectBit-confirmResult");        List<Resources> resList = resService.findByBusinessIdAndFlag(projectId, 11);        List<Resources> otherResList = resService.findByBusinessIdAndFlag(projectId, 12);        AuctionCompareBid auctionCompareBid = auctionCompareBidService.findTopOneByAuctionId(auctionInfo.getId());        mv.addObject("resList", resList);        mv.addObject("otherResList", otherResList);        mv.addObject("projectId", projectId);        mv.addObject("auctionInfo", auctionInfo);        mv.addObject("auctionCompareBid", auctionCompareBid);        String title = "无人竞拍自动流标";        if (auctionCompareBid != null) {            title = auctionInfo.getWinnerName() + "以" + auctionInfo.getHitPrice() + "元中标";        }        mv.addObject("title", title);        return mv;    }    /**     * @description 产权评审纪要页面（产权单位发起）     * @author shy     */    @RequestMapping("/owner/reviewRecord")    public ModelAndView reviewRecord(HttpSession session, String projectId) {        ModelAndView mv = new ModelAndView("/auction/owner/reviewRecord");        AuctionInfo auctionInfo = auctionService.get(AuctionInfo.class, projectId);        SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy年MM月dd日HH:mm时");        int auctionCount = auctionCompareBidService.countDistinctByAuctionId(auctionInfo.getId());        mv.addObject("auctionInfo", auctionInfo);        mv.addObject("auctionStart", sdfTime.format(auctionInfo.getAuctionStart()));//竞拍时间        mv.addObject("auctionCount", auctionCount);        return mv;    }    //先移除指定类型的附件绑定    private void removeAllBindResourcesByFlag(String projectId, Integer flag) {        List<Resources> resList = resService.findByBusinessIdAndFlag(projectId, flag);        for (Resources res : resList) {            if (res != null) {                res.setBusinessId(null);                //res.setFunctionFlog(null);            }        }        this.resService.saveOrUpdate(resList);// 更新    }    //让附件与项目绑定    private void bindResources(String budgetMenuData, String projectId) {        if (budgetMenuData != null) {            String budgetMenuStr[] = budgetMenuData.split(",");            for (String budgetMenuId : budgetMenuStr) {                if (budgetMenuId != null && budgetMenuId.length() > 0) {                    Resources res = resService.get(Resources.class, budgetMenuId);                    if (res != null) {                        res.setBusinessId(projectId);                        //res.setFunctionFlog(flag);                        this.resService.saveOrUpdate(res);// 更新                    }                }            }        }    }    //更新中标公告    private void upBidNotice(WebContent webContent, AuctionInfo auctionInfo) throws Exception {        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");       // User userInfo = userService.get(User.class, auctionInfo.getOwnerId());//        if (userInfo == null) {//            throw new Exception("更新中标或流标公告 获取产权人信息失败 auctionInfo.getOwnerId():" + auctionInfo.getOwnerId());//        }        // 1.使用cms系统发布公告，2.发送提醒信息        WordHandler world = new WordHandler();        Map map = new HashMap();        map.put("auctionInfo", auctionInfo);     //   map.put("userInfo", userInfo);        map.put("createTime", sdf.format(auctionInfo.getCreateTime()));//项目创建时间        map.put("hitShowStart", sdf.format(auctionInfo.getHitShowStart()));// 中标公示期开始时间        map.put("hitShowEnd", sdf.format(auctionInfo.getHitShowEnd().getTime() - 1000));// 中标公示期结束时间        map.put("hitTime", sdf.format(auctionInfo.getHitShowStart()));// 发布时间        //评审纪要        String attachment = "";        List<Resources> resList = resService.findByBusinessIdAndFlag(auctionInfo.getId(), 11);        for (Resources resource : resList) {            attachment += "<a href='../web/fileView?resId=" + resource.getId() + "'>" + resource.getOldName()                    + "</a></br>";        }        map.put("attachment", attachment);// 附件 评审纪要        world.generateWord("hitNotice.html", map, "hitNotice.html");// 生成内容worldXmlPath        File file = new File("hitNotice.html");        String content = "";        try {            content = FileUtils.readFileToString(file, "utf-8");            file.delete();// 删除生成的文件        } catch (IOException e) {            e.printStackTrace();        }        webContent.setType("32");        webContent.setContent(content);        webContentService.saveOrUpdate(webContent);    }    /**     * @description 产权人 提交中标结果     * @author shy     */    @RequestMapping(value = "/owner/confirmProject", method = RequestMethod.POST)    @ResponseBody    public String confirmProject(HttpSession session, String projectId, String confirmReason, String status, String budgetMenuData) {        try {            //去除多余   ,号            if (budgetMenuData != null && budgetMenuData.length() > 0 && budgetMenuData.charAt(0) == ',') {                budgetMenuData = budgetMenuData.substring(1);            }            AuctionInfo pro = auctionService.get(AuctionInfo.class, projectId);            //流程 获取任务            Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());            Map<String, Object> variables = new HashMap<String, Object>();            WebContent webContent = getWebContent(task.getProcessInstanceId());            //先移除评审纪要附件与项目绑定            removeAllBindResourcesByFlag(projectId, 11);            //先移除其他材料附件与项目绑定            removeAllBindResourcesByFlag(projectId, 12);            //让附件与项目绑定            bindResources(budgetMenuData, projectId);            User user = (User) session.getAttribute("loginUser");            int publicity = dataSetService.getDataSet().getPublicity();//公示期            Date date = new Date();            //设置确认人            pro.setConfirmId(pro.getCreateId());            pro.setConfirmName(pro.getCreateName());            pro.setConfirmTime(new Date());            if (status.equals("0")) {                Date showEnd = DateUtils.computeWorkDayDate(holidaySetService, date, publicity);//公示结束时间                pro.setHitShowEnd(showEnd);//中标公示开始时间                pro.setHitShowStart(date);//中标公示结束时间                variables.put("isFlow", Integer.parseInt(status));//通过                upBidNotice(webContent, pro);                workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(), "confirmReason", confirmReason + "</td><th>确认结果</th><td>确认通过");            } else {                int flowPublicity = dataSetService.getDataSet().getFlowPublicity();//流标公示时间                Date flowEndTime = DateUtils.computeWorkDayDate(holidaySetService, date, flowPublicity);//产权人中标结果超时时间                pro.setFlowshowStart(date);//流标公示开始时间                pro.setFlowshowEnd(flowEndTime);//流标公示结束时间                variables.put("isFlow", Integer.parseInt(status));//流标                executionService.genFlowWebContent(webContent, pro);//                pro.setWinnerId(null);//                pro.setWinnerName(null);                if (status.equals("2")) {                    workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(), "confirmReason", confirmReason + "</td><th>确认结果</th><td>无人竞拍自动流标");                } else {                    workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(), "confirmReason", confirmReason + "</td><th>确认结果</th><td>产权人选择流标");                }            }            auctionService.saveOrUpdate(pro);            //直接完成流程            workflowProcessInstanceService.complete(task.getId(), variables);        } catch (Exception ex) {            ex.printStackTrace();            return Constant.UNSUCCESS;        }        return Constant.SUCCESS;    }    /**     * 中心审核人 中标结果审核页面     *     * @param projectId     * @return     */    @RequestMapping("/centerAuditor/viewCenterReslutAudit")    public ModelAndView viewCenterReslutAudit(String projectId) {        ModelAndView mv = new ModelAndView("/auction/center_auditor/auction-center-reslut-audit");        AuctionInfo auctionInfo = this.auctionService.get(AuctionInfo.class, projectId);        Task task = workflowProcessInstanceService.findTask(auctionInfo.getWorkflowId());        String title = "";        int isFlow = (int) runtimeService.getVariable(task.getProcessInstanceId(), "isFlow");        switch (isFlow) {            case Constant.OWNER_CHOOSE_AUCTION_RESLUT_TYPE_SUCCESS:                title = auctionInfo.getWinnerName() + "以" + auctionInfo.getHitPrice() + "元中标";                break;            case Constant.OWNER_CHOOSE_AUCTION_RESLUT_TYPE_FLOW:                title = "产权人选择流标";                break;            case Constant.OWNER_CHOOSE_AUCTION_RESLUT_TYPE_AUTO_FLOW:                title = "无人竞拍自动流标";                break;            case Constant.OWNER_CHOOSE_AUCTION_RESLUT_TYPE_OUT_TIME_FLOW:                title = "因产权单位未在规定时间内确认结果而造成流标";                break;        }        mv.addObject("auctionInfo", auctionInfo);        mv.addObject("title", title);        return mv;    }    /**     * @description 中心审核人 结果审核     * @author shy     */    @RequestMapping(value = "/centerAuditor/centerReslutAudit", method = RequestMethod.POST)    @ResponseBody    public String centerReslutAudit(HttpSession session, String projectId, String reason, Boolean compileAudit) {        try {            AuctionInfo pro = auctionService.get(AuctionInfo.class, projectId);            //流程 任务完成            Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());            Map<String, Object> variables = new HashMap<>();            WebContent webContent = getWebContent(task.getProcessInstanceId());            //直接完成流程            User user = (User) session.getAttribute("loginUser");            if (compileAudit) {                int isFlow = (int) runtimeService.getVariable(task.getProcessInstanceId(), "isFlow");                int publicity = dataSetService.getDataSet().getPublicity();//公示期                Date date = new Date();                if (isFlow == Constant.OWNER_CHOOSE_AUCTION_RESLUT_TYPE_SUCCESS) {                    //判断是否需要推送履约保证金                    if (pro.getTrusteeship() == true && pro.getExecuteDeposit() > 0) {                        // 推送信息至银行（履约保证金）                        boolean executeResult = postBankFromExecute(pro);                        if (!executeResult) {//履约保证金推送失败                            return "履约保证金推送失败";                        }                    }                    Date showEnd = DateUtils.computeWorkDayDate(holidaySetService, new Date(), publicity);//公示结束时间                    String auditor = (String) runtimeService.getVariable(task.getProcessInstanceId(), "auditor");                    List<String> rec = new ArrayList<>();                    rec.add(auditor);//审核人                    rec.add(pro.getCreateId());                    variables.put("release_users", rec);//设置处理人集合                    variables.put("flowDown", false);//是否流标                    variables.put("publishEndTime", StringUtil.getISODate(showEnd));//中标公示结束时间                    pro.setHitShowEnd(showEnd);//中标公示开始时间                    pro.setHitShowStart(date);//中标公示结束时间                    //重新生成中标公告                    upBidNotice(webContent, pro);                    webContent.setEndShowTime(showEnd);// 设置展示结束时间                } else {                    int flowPublicity = dataSetService.getDataSet().getFlowPublicity();//流标公示时间                    Date flowEndTime = DateUtils.computeWorkDayDate(holidaySetService, date, flowPublicity);//产权人中标结果超时时间                    variables.put("flowDown", true);//是否流标                    variables.put("flowEndTime", StringUtil.getISODate(flowEndTime));//流标公示结束时间                    pro.setFlowshowStart(date);//流标公示开始时间                    pro.setFlowshowEnd(flowEndTime);//流标公示结束时间                    pro.setWinnerId(null);                    pro.setWinnerName(null);                    executionService.genFlowWebContent(webContent, pro);                    webContent.setEndShowTime(flowEndTime);// 设置展示结束时间                    //重新生成流标公告                }                webContent.setCreateTime(date);                webContent.setIsDisplay(0);//0 = 显示                webContentService.saveOrUpdate(webContent);                variables.put("pass", true);//是否通过                variables.put("reject", false);//产权人重新确认中标结果 = false                workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(), "centerReslutAuditReason", reason + "</td><th>审核结果</th><td>审核通过");            } else {                variables.put("pass", false);//是否通过                variables.put("reject", true);//产权人重新确认中标结果 = true                int auditTimeout = dataSetService.getDataSet().getAuditTimeout();                String updateEndTime = DateUtils.computeWorkDayDateStr(holidaySetService, new Date(), auditTimeout);//产权人中标结果超时时间                variables.put("updateEndTime", StringUtil.getISODate(updateEndTime));                workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(), "centerReslutAuditReason", reason + "</td><th>审核结果</th><td>审核不通过");            }            pro.setTradeTime(new Date());            auctionService.saveOrUpdate(pro);            workflowProcessInstanceService.complete(task.getId(), variables);//完成任务        } catch (Exception ex) {            ex.printStackTrace();            return Constant.UNSUCCESS;        }        return Constant.SUCCESS;    }    /**     * @param response     * @param request     * @desccription 资产转让合同下载     */    @RequestMapping("/owner/assetTransferContract")    public void assetTransferContract(String projectId, HttpServletResponse response, HttpServletRequest request) {        AuctionInfo pro = auctionService.get(AuctionInfo.class, projectId);        String filePath = request.getSession().getServletContext().getRealPath("/");        String fileRealPath = filePath + "file_resource/";        String FileName = "资产转让(处置)合同模板.docx";        if (pro.getCatagoryId().equals(Constant.PROJECTCATAGORY_RENT)) {            FileName = "租赁合同模板.docx";        }        fileRealPath += FileName;        // 下载文件        FileDownload.processDownload(fileRealPath, FileName, request, response);    }    /**     * @param session     * @param projectId     * @return ModelAndView     * @description 上传合同页面     * @author zhn     * @date 2016-6-21 上午09:42:23     */    @RequestMapping("/owner/uploadAuctionContract")    public ModelAndView uploadAuctionContract(HttpSession session, String projectId, Integer type) {        AuctionInfo pro = auctionService.get(AuctionInfo.class, projectId);        List<Resources> resList = resService.findByBusinessIdAndFlag(projectId, 13);        List<Resources> otherResList = resService.findByBusinessIdAndFlag(projectId, 14);        ModelAndView mv = new ModelAndView("/auction/owner/contract-input");        mv.addObject("project", pro);        mv.addObject("type", type);        mv.addObject("resList", resList);        mv.addObject("otherResList", otherResList);        return mv;    }    /**     * @description 产权人 或 竞拍人上传合同     * @author shy     */    @RequestMapping(value = "/owner/doSubmitContract", method = RequestMethod.POST)    @ResponseBody    public String doSubmitContract(HttpSession session, String projectId, String reason, Boolean compileAudit, String budgetMenuData, java.sql.Date backTime) {        if (validBidBond(projectId) == false) {            return Constant.NO_EXECTUE_DEPOSIT;//未缴纳履约保证金        }        //去除多余   ,号        if (budgetMenuData != null && budgetMenuData.length() > 0 && budgetMenuData.charAt(0) == ',') {            budgetMenuData = budgetMenuData.substring(1);        }        User user = (User) session.getAttribute("loginUser");        AuctionInfo pro = auctionService.get(AuctionInfo.class, projectId);        //流程 获取任务        Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());        //先移除合同附件与项目绑定        removeAllBindResourcesByFlag(projectId, 13);        //先移除中标通知书与项目绑定        removeAllBindResourcesByFlag(projectId, 14);        //让附件与项目绑定        bindResources(budgetMenuData, projectId);        if (backTime != null) {            pro.setBackExecuteTime(backTime);        }        pro.setContactUpTime(new Date());        pro.setContactUpUserId(user.getId());        pro.setContactUpUserName(user.getLoginName());        auctionService.saveOrUpdate(pro);//绑定上传人        //完成任务        workflowProcessInstanceService.complete(task.getId());        return Constant.SUCCESS;    }    /**     * 合同审核页面     *     * @param projectId     * @return     */    @RequestMapping("/centerAuditor/viewContractAuditInput")    public ModelAndView viewContractAudit(String projectId) {        ModelAndView mv = new ModelAndView("/auction/center_auditor/contractaudit-input");        AuctionInfo pro = auctionService.get(AuctionInfo.class, projectId);        mv.addObject("project", pro);        return mv;    }    //获取不带扩展名的文件名    private String getFileNameNoEx(String filename) {        if ((filename != null) && (filename.length() > 0)) {            int dot = filename.lastIndexOf('.');            if ((dot > -1) && (dot < (filename.length()))) {                return filename.substring(0, dot);            }        }        return filename;    }    /**     * 生成合同公示     *     * @param pi     * @return     */    @SuppressWarnings("all")    private WebContent generateContractPublicity(AuctionInfo pro) {        WordHandler world = new WordHandler();        Map map = new HashMap();        // 合同附件        String resName = "";        List<Resources> resList = resService.findByBusinessIdAndFlag(pro.getId(), 13);        for (Resources resource : resList) {            resName += "<a href='../web/fileView?resId=" + resource.getId() + "'>" + resource.getOldName()//resource.getOldName()                    + "</a><br/> ";        }//        //中标通知书//        resList = resService.findByBusinessIdAndFlag(pro.getId(), 14);//        for (Resources resource : resList) {//            resName += "<a href='../web/fileView?resId=" + resource.getId() + "'>" + resource.getOldName() + "-合同"//resource.getOldName()//                    + "</a><br/> ";//        }        map.put("resName", resName);        //生成内容        world.generateWord("contractPublicity.html", map, "contractPublicity.html");// 生成内容worldXmlPath        File file = new File("contractPublicity.html");        String content = "";        try {            content = FileUtils.readFileToString(file, "utf-8");            file.delete();// 删除生成的文件        } catch (IOException e) {            e.printStackTrace();        }        WebContent web = new WebContent();        // 标题        String title = "【" + pro.getCatagoryName() + "】 " + pro.getAuctionName() + "（" + pro.getCode() + "）合同公告";        web.setTitle(title);        web.setContent(content);        web.setCreaterId(ActivitiMap.SUPERADMIN_ID);        web.setCreateTime(pro.getContactshowStart());        web.setCreaterName("系统");        web.setDeptId("1");        web.setProjectId(pro.getId());        web.setType("41");        web.setIsDisplay(0);//显示        web.setEndShowTime(pro.getContactshowEnd());// 设置展示结束时间        return web;    }    /**     * 项目合同审核操作     *     * @param projectId     * @return     */    @RequestMapping("/centerAuditor/contractAudit")    @ResponseBody    public String contractAudit(HttpSession session, String projectId, String reason, Integer contactPass) throws Exception {        User user = (User) session.getAttribute("loginUser");        AuctionInfo pro = auctionService.get(AuctionInfo.class, projectId);        //流程 获取任务        Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());        Map<String, Object> variables = new HashMap<String, Object>();        if (contactPass == 0)//通过        {            // 设置合同公示时间            // 获取时间            int publicity = dataSetService.getDataSet().getContractPublicity();//合同公示期            Date date = new Date();            Date showEnd = DateUtils.computeWorkDayDate(holidaySetService, new Date(), publicity);//公示结束时间            variables.put("contractAuditPass", true);//审核通过            variables.put("publishContactEndTime", StringUtil.getISODate(showEnd));            // 保存合同开始时间，结束时间            pro.setContactshowStart(date);            pro.setContactshowEnd(showEnd);            WebContent webContent = generateContractPublicity(pro);            webContentService.saveOrUpdate(webContent);            variables.put("contractPublicityId", webContent.getId());            auctionService.saveOrUpdate(pro);            // 保存审核意见            workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(), "contract_audit",                    reason + "</td><th>审核结果</th><td>审核通过");        } else {            variables.put("contractAuditPass", false);//审核不通过            // 保存审核意见            workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(), "contract_audit",                    reason + "</td><th>审核结果</th><td>审核不通过");        }        //直接完成流程        workflowProcessInstanceService.complete(task.getId(), variables);        return Constant.SUCCESS;    }    /**     * @param projectId     * @return     * @description中心审核人解除合同上传锁定（解锁）     * @author shy     */    @RequestMapping("/centerAuditor/unlockContract")    @ResponseBody    public String unlockContract(HttpSession session, String projectId) {        AuctionInfo pro = auctionService.get(AuctionInfo.class, projectId);        Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());        Map<String, Object> variables = new HashMap<>();        Date upContactEndTime = DateUtils.computeWorkDayDate(holidaySetService, new Date(), 60);//合同上传超时时间 60个工作日        variables.put("upContactEndTime", StringUtil.getISODate(upContactEndTime));//设置60天超时时间        workflowProcessInstanceService.complete(task.getId(), variables);        return Constant.SAVE_SUCCESS;    }    /**     * @param     * @return     * @throws Exception     * @description 提交评标补录资料     * @author shy     * @date 2017年6月29日     */    @RequestMapping("/doSupplementFileData")    @ResponseBody    public String doSupplementFileData(String projectId, String budgetMenuData) throws Exception {        //先移除补录资料与项目绑定        removeAllBindResourcesByFlag(projectId, 15);        //让附件与项目绑定        bindResources(budgetMenuData, projectId);        return Constant.SUCCESS;    }    /**     * @param projectId     * @return     * @description 发放中标通知书     * @author wwang     * @date 2016-8-24     */    @RequestMapping("/centerAuditor/noticBidInfo")    @ResponseBody    public String noticBidInfo(String projectId) {        AuctionInfo pro = auctionService.get(AuctionInfo.class, projectId);        pro.setReleaseAlertDoc(new Date());        this.projectInfoService.saveOrUpdate(pro);        Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());        Map<String, Object> variables = new HashMap<String, Object>();        List<String> rec = new ArrayList<String>();        rec.add(pro.getCreateId());//设置上传合同人的集合        rec.add(pro.getWinnerId());        variables.put("receivers", rec);        Date upContactEndTime = DateUtils.computeWorkDayDate(holidaySetService, new Date(), 60);//合同上传超时时间 60个工作日        variables.put("upContactEndTime", StringUtil.getISODate(upContactEndTime));//设置60天超时时间        workflowProcessInstanceService.complete(task.getId(), variables);        return Constant.SUCCESS;    }    /**     * 中标通知书列表页面     *     * @param projectId     * @return     */    @RequestMapping("/viewPrintWinbidAlert")    public ModelAndView viewPrintWinbidAlert(HttpSession session, String projectId, Boolean isShow, String bidId) {        User user = (User) session.getAttribute("loginUser");        AuctionInfo pro = auctionService.get(AuctionInfo.class, projectId);        //判断是否为投标用户        ModelAndView mv = new ModelAndView("/auction/center_auditor/winbid-alert-print");        mv.addObject("pro", pro);        return mv;    }    /**     * 补录资料页面     *     * @param projectId     * @return     */    @RequestMapping("/viewWupplementData")    public ModelAndView viewWupplementData(HttpSession session, String projectId) {        ModelAndView mv = new ModelAndView("/auction/center_auditor/supplement-Data-input");        AuctionInfo auctionInfo = auctionService.get(AuctionInfo.class, projectId);        //List<Resources> resList = resService.findByBusinessIdAndFlag(projectId, 11);        List<Resources> otherResList = resService.findByBusinessIdAndFlag(projectId, 15);//获取补录资料列表        //mv.addObject("resList", resList);        mv.addObject("otherResList", otherResList);        mv.addObject("auctionInfo", auctionInfo);        return mv;    }    /**     * @param session     * @param projectId     * @return     * @description 进入退还保证金页面     * @author shy     */    @RequestMapping("/leader/returnDepositPage")    public ModelAndView returnDepositPage(HttpSession session, String projectId) {        boolean showBidFlag = false;// 是否显示中标保证金明细        boolean showButtonFlag = false;// 是否显示保证金完成按钮        AuctionInfo projectInfo = auctionService.get(AuctionInfo.class, projectId);        boolean Bidflag = winningDepositShowByProjectStatus(projectInfo.getStatus());//根据状态显示中标人信息        ModelAndView mv = new ModelAndView();        String winningId = projectInfo.getWinnerId();        boolean isflowstatus = flowStatusDepositButton(projectInfo.getStatus());        if(projectInfo.getTrusteeship()==true){             boolean ifPayDeposit = isPayDepositReturn(projectInfo); // 判断履约保证金是否缴纳            if (ifPayDeposit == true ||projectInfo.getExecuteDeposit()==0.00) {             showBidFlag = true;             showButtonFlag = true;            }        }else if (winningId != null && Bidflag) {// 有中标人             showBidFlag = true;             showButtonFlag = true;        }        if(isflowstatus){             showButtonFlag = true;        }        mv.setViewName("/auction/finance/deposit-list");        mv.addObject("projectId", projectId);        mv.addObject("isShowBid", showBidFlag);        mv.addObject("showButtonFlag", showButtonFlag);        return mv;    }    /**     * @param session     * @param projectId     * @return     * @description 进入保证金明细证金页面     * @author shy     */    @RequestMapping("/leader/returnDepositDetailPage")    public ModelAndView returnDepositDetail(HttpSession session, String projectId) {        boolean showBidflag = false;        AuctionInfo projectInfo = projectInfoService.get(AuctionInfo.class, projectId);        ModelAndView mv = new ModelAndView();        String winningId = projectInfo.getWinnerId();        if (winningId != null) {            showBidflag = true;        }        mv.setViewName("/auction/finance/deposit-detail");        mv.addObject("projectId", projectId);        mv.addObject("isShowBid", showBidflag);        return mv;    }    /**     * 保存系统外用户保证金信息     */    private void saveOutDeposit(Bank bank, AuctionInfo proj, int depositType) {        //组装        ComposeIdPK2 pk = new ComposeIdPK2();        pk.setCompanyName(bank.getInName());        pk.setHstSeqNum(bank.getHstSeqNum());        pk.setProjectId(proj.getId());        pk.setDepositType(depositType);        //查询数据库中是否有此信息        DepositReturnOut depositReturn = depositReturnService.get(DepositReturnOut.class, pk);        if (depositReturn == null) {            depositReturn = new DepositReturnOut();            depositReturn.setReturnOpt(0);// 默认为未提交申请            depositReturn.setStatus(0);// 默认为未退还        }        depositReturn.setPk(pk);        depositReturn.setProjectType(proj.getCatagoryName());        depositReturn.setBiaoDuanNo(proj.getId());// 标段号        depositReturn.setProjectName(proj.getAuctionName());        depositReturn.setProjectCode(proj.getCode());        depositReturn.setTnAmount(new BigDecimal(bank.getInAmount()));        depositReturn.setBankName(bank.getInName());        String date = "";        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");        date = bank.getInDate() + bank.getInTime(); // 拼接日期        try {            depositReturn.setTransTime(simpleDateFormat.parse(date));//缴费时间        } catch (ParseException e) {            e.printStackTrace();        }// 时间        depositReturn.setInAcct(bank.getInAcct());        depositReturn.setBid(false);    // 默认为未投标        depositReturn.setAddWord(bank.getAddWord());        depositReturnService.saveOrUpdate(depositReturn);    }    /**     * @description 根据状态显示中标人信息     * @author shy     * @date 2016年10月28日     */    private boolean winningDepositShowByProjectStatus(Integer status) {        List<Integer> list = new ArrayList<Integer>();        list.addAll(Arrays.asList(//                Integer.valueOf(ProjectStatusAuction.AUDIT_CONTRACT.toString()),//                Integer.valueOf(ProjectStatusAuction.CONTRACT_AUDIT_NOPASS.toString()),                Integer.valueOf(ProjectStatusAuction.SHOW_CONTRACT.toString()),                Integer.valueOf(ProjectStatusAuction.LOCK_CONTRACT.toString()),                Integer.valueOf(ProjectStatusAuction.UP_CONTACT.toString()),                Integer.valueOf(ProjectStatusAuction.END.toString())        ));        return list.contains(status);    }    /**     * description 判断履约保证金是否缴纳     * author shy     * date 2017-2-8     */    private boolean isPayDepositReturn(AuctionInfo projectInfo) {        boolean result = false;        if (projectInfo.getExecuteBankAuthCode() == null) {            result = false;        } else {            List<Bank> bidBondInfoList = depositExecuteService.getDepositList(projectInfo.getId());            if (bidBondInfoList != null && bidBondInfoList.size() > 1) {//系统默认生成一条空记录所有size>1                for (Bank bank : bidBondInfoList) {                    if (bank.getInName() != null ) {//                    if (bank.getInName() != null && bank.getInName().equals(projectInfo.getWinnerName())) {                            result = true;                    }                }            }        }        return result;    }    /**     * @param projectId     * @param resp     * @param page     * @throws IOException     * @throws ParseException     * @description 获取投标人保证金信息列表     * @author shy     */    @RequestMapping("/leader/getProjectBidList")    @ResponseBody    public void getProjectBidList(String projectId, HttpServletResponse resp, Page page, Integer type)            throws IOException, ParseException {        AuctionInfo projectInfo = this.projectInfoService.get(AuctionInfo.class, projectId);        // 1.获取中标人的信息（中标人的loginName）        String bidderName = projectInfo.getWinnerName();        // 2.查DepositReturn 表是否有数据，如果没有那么从银行接口获取数据        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");		List<Bank> bankreturnList = depositService.getDepositList(projectId);		if (bankreturnList!=null) {			System.out.println("AuctionBidController.getProjectBidList()-------------->bankreturnList: "+bankreturnList.size());			for (Bank bank : bankreturnList) {			    if(bank.getHstSeqNum()!=null){				ComposeIdPK composeIdPK = new ComposeIdPK();				composeIdPK.setCompanyName(bank.getInName());				composeIdPK.setProjectId(projectId);				composeIdPK.setDepositType(Constant.DEPOSIT_TYPE_BIDDER);				composeIdPK.setHstSeqNum(bank.getHstSeqNum());//交易流水号				//DepositReturn depositReturn = depositReturnService.get(DepositReturn.class, composeIdPK);                DepositReturn depositReturn = depositReturnService.getDepositListByHstSeqNum(bank.getHstSeqNum());				//如果数据库里面取出的保证金对象主键中的单位名称与银行返回的InName 不一致，则删除现有的保证金对象，重新写入保证金对象				if(depositReturn != null&&!depositReturn.getPk().getCompanyName().equals(bank.getInName())){                      depositReturn=depositReturnService.updateDepositReturnPK(depositReturn,composeIdPK);				}				if (depositReturn == null) {					depositReturn = new DepositReturn();					RegisterUser rUser=null;					if(bank.getInName()!=null){					  List<RegisterUser> lst =registerUserService.getSameAccountUser(bank.getInAcct());				       if(lst.size()>0){                           rUser=lst.get(0);                        }					}					if (rUser == null) {						// 未查到相关数据，系统记录与银行数据不一致，记录系统日志，并忽略这条记录						// 记住修改log表的content为varchar(2000)//						LogInfo log1 = new LogInfo("从银行返回的数据中查找不到用户信息" + bank.getInName(), "", "",//								String.valueOf(LogUtil.LogType.ADD.ordinal()), "ProjectBidController.class", "");//						LogUtil.addLog(log1);						if(bank.getInName()==null || bank.getInName().equals("")){							continue;  //不符合条件，不需要写值，直接跳过						}						this.saveOutDeposit(bank, projectInfo,Constant.DEPOSIT_TYPE_BIDDER);						continue;					}					if(rUser!=null && !bank.getInAcct().equals(rUser.getAccount())){//系统账号的银行卡号和bank的卡号不一致						//未查到相关数据，系统记录与银行数据不一致，记录系统日志，并忽略这条记录//				        LogInfo log1= new LogInfo("从银行返回的数据中的银行卡号和注册账号卡号不一致： "+bank.getInName(),"","",//				        		String.valueOf(LogUtil.LogType.ADD.ordinal()), "QuartZAll.class", "");				      //  LogUtil.addLog(log1);						if(bank.getInName()==null || bank.getInName().equals("")){							continue;  //不符合条件，不需要写值，直接跳过						}	    				//如果发现这个用户的系统账号的银行卡号和bank的卡号不一致，调用系统外用户	    				this.saveOutDeposit(bank, projectInfo,Constant.DEPOSIT_TYPE_BIDDER);						continue;					}					ComposeIdPK composeIdPK2 = new ComposeIdPK();					composeIdPK2.setCompanyName(bank.getInName());					composeIdPK2.setProjectId(projectId);					composeIdPK2.setDepositType(Constant.DEPOSIT_TYPE_BIDDER);					depositReturn.setBankName(rUser.getBank());					depositReturn.setProjectType(projectInfo.getCatagoryName());					depositReturn.setPk(composeIdPK);					depositReturn.setBidderId(rUser.getId());					depositReturn.setBiaoDuanNo(projectId); // 标段号					depositReturn.setProjectName(projectInfo.getAuctionName());					depositReturn.setReturnOpt(0); // 默认为未提交申请					depositReturn.setStatus(0); // 默认为未退还					depositReturn.setProjectCode(projectInfo.getCode());					depositReturn.setTnAmount(new BigDecimal(bank.getInAmount())); // 金额					depositReturn.setTransTime(simpleDateFormat.parse(bank.getInDate() + bank.getInTime())); // 时间格式：//// 2016-10-19//// 12:10:37					//depositReturn.setHstSeqNum(bank.getHstSeqNum());					composeIdPK2.setHstSeqNum(bank.getHstSeqNum());//交易流水号					depositReturn.setInAcct(bank.getInAcct());					depositReturn.setIsBid(false); // 默认为未投标					if(bank.getAddWord()!=null){//获取中间值						depositReturn.setAddWord(bank.getAddWord());					}else {						depositReturn.setAddWord("");					}					this.auctionBidService.saveOrUpdate(depositReturn);				} else {					depositReturn.setTnAmount(new BigDecimal(bank.getInAmount()));				}			}			}		}        this.auctionBidService.getUnBidDepositReturn(projectId, bidderName, page, type);        List<DepositReturn> drList = (List<DepositReturn>) page.getResult();        for (DepositReturn dr : drList) {             User u = userService.getUserByRegisterId(dr.getBidderId());            List<AuctionCompareBid> list = auctionCompareBidService.findAllByAuctionIdAndBiddrId(projectInfo.getId(),u.getId() );            if (list.size() > 0) {                dr.setIsBid(true); // 设置已投标            }        }        JSONObject jsonObject = CommUtil.getPageJSONData(page, true);        resp.getWriter().print(jsonObject);    }    /**     * @return     * @description 退还保证金     * @author shy     */    @RequestMapping("/leader/returnDeposit")    @ResponseBody    @Transactional    public String returnDeposit(String projectId, String projectName, String bidderId, String hstSeqNum,String companyName) {       // String bidderName = "";        String result = "";        //获取biddername;        ComposeIdPK pk = new ComposeIdPK();        //companyName = this.registerUserService.get(RegisterUser.class, bidderId).getLoginName();        pk.setCompanyName(companyName);        pk.setHstSeqNum(hstSeqNum);        pk.setProjectId(projectId);        pk.setDepositType(0);        DepositReturn depositReturn = depositReturnService.get(DepositReturn.class, pk);        AuctionInfo projectInfo = this.projectInfoService.get(AuctionInfo.class, projectId);        if (bidderId.equals(projectInfo.getWinnerId())) {            List<DepositReturn> executeDeposit = this.depositReturnService.getExcuteDeposit(projectId, bidderId, Constant.DEPOSIT_TYPE_EXECUTE);            if (executeDeposit.isEmpty()) {                return Constant.NO_EXECTUE_DEPOSIT;            }        }        //设置延迟        final ExecutorService exec = Executors.newFixedThreadPool(1);        try {            Future<String> future = exec.submit(new AuctionBidController.BankResult(projectId, projectName, companyName, bidderId, pk));            Integer bankResult = Integer.parseInt(future.get(8000, TimeUnit.MILLISECONDS)); //设置8秒            if (bankResult == 1) {                depositReturn.setReturnOpt(1);//银行返回1 申请退还成功                this.depositReturnService.saveOrUpdate(depositReturn);                result = Constant.SAVE_SUCCESS;            } else if (bankResult == 0) {//银行返回0 申请退还失败                depositReturn.setReturnOpt(2);                this.depositReturnService.saveOrUpdate(depositReturn);                result = Constant.SAVE_UN_SUCCESS;            }            System.out.println("银行回调成功....");        } catch (Exception e) {            depositReturn.setReturnOpt(-1);//超时未返回            this.depositReturnService.saveOrUpdate(depositReturn);            System.out.println("银行回调超时....");            result = Constant.BANK_TIME_OUT;        }        exec.shutdown();        return result;    }    class BankResult implements Callable<String> {        private String projectId;        private String projectName;        private String bidderName;        private String bidderId;        private ComposeIdPK pk;        public BankResult(String projectId, String projectName, String bidderName, String bidderId, ComposeIdPK pk) {            this.projectId = projectId;            this.bidderName = bidderName;            this.projectName = projectName;            this.bidderId = bidderId;            this.pk = pk;        }        @Override        public String call() throws Exception {             int result = depositService.returnDepositByProj(bidderId, projectId, bidderName, projectName, pk);            return String.valueOf(result);        }    }    /**     * @description 进入履约保证金明细页面     * @author shy     * @date 2016-12-23     */    @RequestMapping("/finance/excuteDepositList")    @ResponseBody    public ModelAndView excuteDepositList(HttpSession session, String projectId) {        AuctionInfo projectInfo = projectInfoService.get(AuctionInfo.class, projectId);        ModelAndView mv = new ModelAndView("/auction/finance/excute-deposit-show");        mv.addObject("projectId", projectId);        mv.addObject("bidderId", projectInfo.getWinnerId());        List<Resources> resList = FileResUtil.findResources(projectInfo.getId());        for (Resources resources : resList) {			if (resources.getFunctionFlog() == 50) {			 mv.addObject("resId",resources.getId());			}		}        return mv;    }    /**     * @throws ParseException     * @Description 获取项目履约保证金信息     * @author shy     * @date 2016-12-26     */    @RequestMapping("finance/getExscuteDeposit")    @ResponseBody    public JSONObject getExscuteDeposit(HttpSession session, String projectId, Page page) throws ParseException {        AuctionInfo projectInfo = projectInfoService.get(AuctionInfo.class, projectId);        //获取履约保证金信息        depositReturnService.getExcuteDepositList(projectId, Constant.DEPOSIT_TYPE_EXECUTE, page);        List<DepositReturn> listPage = (List<DepositReturn>) page.getResult();        for (DepositReturn dr : listPage) {            dr.setIsBid(true); // 设置已投标        }        return CommUtil.getPageJSONData(page, true);    }    /**     * @return     * @description 退还履约保证金     * @author shy     */    @RequestMapping("/finance/returnExecuteDeposit")    @ResponseBody    @Transactional    public String returnExecuteDeposit(String projectId, String projectName, String bidderId, String hstSeqNum, String budgetMenuData, HttpServletRequest request,String companyName) {        String result = "";       // String bidderName = "";        //获取biddername;        //bidderName = this.registerUserService.get(RegisterUser.class, bidderId).getLoginName();        ComposeIdPK pk = new ComposeIdPK();        pk.setDepositType(Constant.DEPOSIT_TYPE_EXECUTE);        pk.setHstSeqNum(hstSeqNum);        pk.setProjectId(projectId);        pk.setCompanyName(companyName);        DepositReturn depositReturn = this.depositReturnService.get(DepositReturn.class, pk);        if (depositReturn.getStatus() == Constant.DEPOSIT_RETURN) {            return String.valueOf(Constant.DEPOSIT_RETURN);        } else if (depositReturn.getStatus() == Constant.DEPOSIT_DEDUCT) {            return String.valueOf(Constant.DEPOSIT_DEDUCT);        }        //设置延迟        final ExecutorService exec = Executors.newFixedThreadPool(1);        try {            Future<String> future = exec.submit(new AuctionBidController.ExecuteDepositBankResult(projectId, projectName, companyName, bidderId, pk));            Integer bankResult = Integer.parseInt(future.get(8000, TimeUnit.MILLISECONDS)); //设置8秒            if (bankResult == 1) {                depositReturn.setReturnOpt(1);//银行返回1 申请退还成功                this.depositReturnService.saveOrUpdate(depositReturn);                result = Constant.SAVE_SUCCESS;            } else if (bankResult == 0) {//银行返回0 申请退还失败                depositReturn.setReturnOpt(2);                this.depositReturnService.saveOrUpdate(depositReturn);                result = Constant.SAVE_UN_SUCCESS;            }            System.out.println("银行回调成功....");        } catch (Exception e) {            depositReturn.setReturnOpt(-1);//超时未返回            this.depositReturnService.saveOrUpdate(depositReturn);            result = Constant.BANK_TIME_OUT;            System.out.println("银行回调超时....");        }        exec.shutdown();        List<Resources> resList = FileResUtil.findResources(projectId);		// 删除已有的附件		for (Resources resources : resList) {			if (resources.getFunctionFlog() == 50) {				FileResUtil.deleteFile(resources.getId(), request);			}		}         //项目关联清单附件信息            String budgetMenuStr[] = budgetMenuData.split(",");            Resources res = null;            for (String budgetMenuId : budgetMenuStr) {                res = FileResUtil.getResources(budgetMenuId);                if (res != null) {                    res.setBusinessId(projectId);                    this.depositReturnService.saveOrUpdate(res);                }            }        return result;    }    class ExecuteDepositBankResult implements Callable<String> {        private String projectId;        private String projectName;        private String bidderName;        private String bidderId;        private ComposeIdPK pk;        public ExecuteDepositBankResult(String projectId, String projectName, String bidderName, String bidderId, ComposeIdPK pk) {            this.projectId = projectId;            this.bidderName = bidderName;            this.projectName = projectName;            this.bidderId = bidderId;            this.pk = pk;        }        @Override        public String call() throws Exception {            int result = executeDepositService.sendReturnDeposit(bidderId, projectId, bidderName, projectName, pk);            return String.valueOf(result);        }    }    /**     * @description 进入履约保证金金页面     * @author shy     * @date 2016-12-23     */    @RequestMapping("/finance/excuteDepositPage")    @ResponseBody    public ModelAndView excuteDepositPage(HttpSession session, String projectId) {        boolean showReturnFlag = false;// 是否显示保证金完成按钮        AuctionInfo projectInfo = projectInfoService.get(AuctionInfo.class, projectId);        if (projectInfo.getFinishExecuteDesposit() == 0) {            showReturnFlag = excuteDepositButtionByProjectStatus(projectInfo.getStatus());        }        ModelAndView mv = new ModelAndView("/auction/finance/excute-deposit-list");        mv.addObject("projectId", projectId);        mv.addObject("showButtonFlag", showReturnFlag);        mv.addObject("bidderId", projectInfo.getWinnerId());        return mv;    }    /**     * @description 判断退还履约保证按钮出现状态是否在列举的状态中存在     * @author shy     * @date 2016年12月23日     */    private boolean excuteDepositButtionByProjectStatus(Integer status) {        List<Integer> list = new ArrayList<Integer>();        list.addAll(Arrays.asList(                Integer.valueOf(ProjectStatusAuction.END.toString()),//结项                Integer.valueOf(ProjectStatusAuction.FLOW.toString()),//流标                Integer.valueOf(ProjectStatusAuction.TERMINAL.toString())));//撤销        return list.contains(status);    }    /**     * @param projectId     * @description 根据projectId 获取所有退还保证金信息     * @author shy     */    @RequestMapping("/leader/getReturnList")    @ResponseBody    public String getReturnList(String projectId, int depositType) {        String result = "";        List<DepositReturn> list = this.depositReturnService.getReturnList(projectId, depositType);        for (DepositReturn depositReturn : list) {            if (depositReturn.getReturnOpt() == 1 && depositReturn.getStatus() == Constant.DEPOSIT_UN_RETURN) { //已提交，未退还                result = Constant.UN_PASS;                return result;            }        }        for (DepositReturn depositReturn : list) {            if (depositReturn.getReturnOpt() == 1 && depositReturn.getStatus() == Constant.FAILE_RETURN) { //已提交，退还不成功                result = Constant.UN_ALL_RERURN;                return result;            }        }        for (DepositReturn depositReturn : list) {            if (depositReturn.getReturnOpt() == 2 || depositReturn.getReturnOpt() == 0 || depositReturn.getReturnOpt() == -1) {                result = Constant.UN_ALL_RERURN;                return result;            }        }        return result = Constant.ALL_RERURN;    }    /**     * @return     * @description 完成保证金操作     * @author shy     */    @RequestMapping("/leader/finishDepositReturn")    @ResponseBody    public String finishDepositReturn(String projectId, int depositType) {        AuctionInfo projectInfo = this.projectInfoService.get(AuctionInfo.class, projectId);        List<DepositReturn> UnOptList = this.depositReturnService.getUnOptList(projectId, depositType);        if (!UnOptList.isEmpty()) {            for (DepositReturn depositReturn : UnOptList) {                depositReturn.setStatus(2);                depositReturn.setUpdateTime(new Date());                this.depositReturnService.saveOrUpdate(depositReturn);            }        }        if (depositType == 0) {            projectInfo.setReturnDepositFlag(true);        } else if (depositType == 1) {            projectInfo.setFinishExecuteDesposit(1);        }        this.auctionService.saveOrUpdate(projectInfo);        return Constant.SAVE_SUCCESS;    }    /**     * @description 进入终止页面     * @author shy     */    @RequestMapping("/bizmanager/canclePage")    public ModelAndView canclePage(HttpSession session, String projectId) {        ModelAndView mv = new ModelAndView("/auction/bizmanager/projectBit-cancle");        mv.addObject("projectId", projectId);        return mv;    }    /**     * @description 终止项目进程     * @author shy     */    @RequestMapping("/bizmanager/closeProject")    @ResponseBody    public String closeProject(HttpSession session, String projectId, String budgetMenuData, String cancelReason, Integer status) {        AuctionInfo pro = auctionService.get(AuctionInfo.class, projectId);        pro.setStatus(status);// 状态显示为撤销或者流标        pro.setWinnerId(null);        pro.setWinnerName(null);        pro.setTradeTime(new Date());//交易时间        pro.setCancelReason(cancelReason);// 撤销理由        this.workflowProcessInstanceService.suspendProcess(pro.getWorkflowId());        this.auctionService.saveOrUpdate(pro);        // 项目关联清单附件信息        if (budgetMenuData != null) {            String budgetMenuStr[] = budgetMenuData.split(",");            Resources res = null;            for (String budgetMenuId : budgetMenuStr) {                res = FileResUtil.getResources(budgetMenuId);                if (res != null) {                    res.setBusinessId(pro.getId());                    res.setFunctionFlog(status);                    this.projectInfoService.saveOrUpdate(res);// 更新                }            }        }        return Constant.DEL_SUCCESS;    }    /**     * @param id     * @return     * @description 质疑/投诉/答复/处理结果 页面     * @author wwang     * @date 2016年9月18日     */    @RequestMapping("/leader/oppugnInput")    public ModelAndView oppugnInput(String id) {        ModelAndView mv = new ModelAndView("/auction/center_auditor/auction-oppugn-input");        mv.addObject("projectId", id);        return mv;    }    /**     * @throws Exception     * @description 是否为工作日, 且超过20个工作日     * @author shy     */    @RequestMapping("/isWorkDayJ")    @ResponseBody    public boolean isWorkDayJ(Date date, Date validTime) throws Exception {        boolean flag = true;        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");        int auctionPublicity = dataSetService.getDataSet().getAuctionPublicity();//竞价公示期        Calendar calStart = Calendar.getInstance();        calStart.setTime(date);        List<String> dates = this.holidaySetService.findAllByYear(calStart.get(Calendar.YEAR) + "");        if (dates.contains(sdf1.format(calStart.getTime()))) {            flag = false;        } else {            //当前时间            Calendar cd = Calendar.getInstance();            cd.setTime(new Date());            cd.add(Calendar.DATE, 1);// 增加天数            String validTimeStr = sdf1.format(cd.getTime()) + " 00:00:00";            //开标时间            Calendar cdBid = Calendar.getInstance();            cdBid.setTime(sdf1.parse(validTimeStr));            //相隔天数            long betweenDay = (calStart.getTime().getTime() - cdBid.getTime().getTime()) / (1000 * 3600 * 24);            int index = 0;            while (betweenDay + 1 > 0) {                if (!dates.contains(sdf1.format(calStart.getTime()))) {                    index++;                }                calStart.add(Calendar.DAY_OF_YEAR, -1);                betweenDay--;            }            if (index <= auctionPublicity) {//超过三天                flag = false;            }        }        return flag;    }    /**     * @throws Exception     * @description 是否为工作日, 且超过20个工作日     * @author shy     */    @RequestMapping("/isWorkDayZ")    @ResponseBody    public boolean isWorkDayZ(Date date, Date validTime) throws Exception {        boolean flag = true;        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");        int publicity = dataSetService.getDataSet().getPublicity();//中标        Calendar calStart = Calendar.getInstance();        calStart.setTime(date);        List<String> dates = this.holidaySetService.findAllByYear(calStart.get(Calendar.YEAR) + "");        if (dates.contains(sdf1.format(calStart.getTime()))) {            flag = false;        } else {            //当前时间            Calendar cd = Calendar.getInstance();            cd.setTime(new Date());            cd.add(Calendar.DATE, 1);// 增加天数            String validTimeStr = sdf1.format(cd.getTime()) + " 00:00:00";            //开标时间            Calendar cdBid = Calendar.getInstance();            cdBid.setTime(sdf1.parse(validTimeStr));            //相隔天数            long betweenDay = (calStart.getTime().getTime() - cdBid.getTime().getTime()) / (1000 * 3600 * 24);            int index = 0;            while (betweenDay + 1 > 0) {                if (!dates.contains(sdf1.format(calStart.getTime()))) {                    index++;                }                calStart.add(Calendar.DAY_OF_YEAR, -1);                betweenDay--;            }            if (index <= publicity) {//超过三天                flag = false;            }        }        return flag;    }    /**     * @throws Exception     * @description 是否为工作日, 且超过21个工作日     * @author shy     */    @RequestMapping("/isWorkDayAuction")    @ResponseBody    public boolean isWorkDayAuction(Date date, Date validTime) throws Exception {        boolean flag = true;        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");        int auctionPublicity = dataSetService.getDataSet().getAuctionPublicity();//竞价公示期        int projectAuditTimeout = dataSetService.getDataSet().getProjectAuditTimeout();        int auctionDays = auctionPublicity + projectAuditTimeout;        Calendar calStart = Calendar.getInstance();        calStart.setTime(date);        List<String> dates = this.holidaySetService.findAllByYear(calStart.get(Calendar.YEAR) + "");        if (dates.contains(sdf1.format(calStart.getTime()))) {            flag = false;        } else {            //当前时间            Calendar cd = Calendar.getInstance();            cd.setTime(new Date());            cd.add(Calendar.DATE, 1);// 增加天数            String validTimeStr = sdf1.format(cd.getTime()) + " 00:00:00";            //开标时间            Calendar cdBid = Calendar.getInstance();            cdBid.setTime(sdf1.parse(validTimeStr));            //相隔天数            long betweenDay = (calStart.getTime().getTime() - cdBid.getTime().getTime()) / (1000 * 3600 * 24);            int index = 0;            while (betweenDay + 1 > 0) {                if (!dates.contains(sdf1.format(calStart.getTime()))) {                    index++;                }                calStart.add(Calendar.DAY_OF_YEAR, -1);                betweenDay--;            }            if (index <= auctionDays) {                flag = false;            }        }        return flag;    }    /**     * @description 判断是否在合同审核过后的状态     * @author wwang     * @date 2016年9月18日     */    private boolean afterAuditContract(Integer status) {        List<Integer> list = new ArrayList<Integer>();        list.addAll(Arrays.asList(                Integer.valueOf(ProjectStatusAuction.SHOW_CONTRACT.toString()),                Integer.valueOf(ProjectStatusAuction.LOCK_CONTRACT.toString()),                Integer.valueOf(ProjectStatusAuction.END.toString())));        return list.contains(status);    }    /**     * 变更公告页面     *     * @param projectId     * @return     */    @RequestMapping("/leader/editPublish")    public ModelAndView editPublish(String projectId) {        ModelAndView mv = new ModelAndView("/auction/center_auditor/editPublish-input");        AuctionInfo project = auctionService.get(AuctionInfo.class, projectId);        DataSet dataset = auctionService.get(DataSet.class, Constant.DATASET_ID);        mv.addObject("project", project);        mv.addObject("dataset", dataset);        return mv;    }    /**     * 推送信息至银行操作（履约保证金）     *     * @return     */    public boolean postBankFromExecute(AuctionInfo pi) {        // 第一次        int n = 1;        try {            int _ret = depositExecuteService.regToBank(pi.getId());            if (_ret == 1) {                System.out.print("注册成功!");                return true;            } else {                System.out.print("注册 不成功");                n++;            }        } catch (IOException e) {            System.out.print("注册 不成功，出现异常");            e.printStackTrace();            n++;        }        // 第二次        try {            int _ret = depositExecuteService.regToBank(pi.getId());            if (_ret == 1) {                System.out.print("第二次注册成功!");                return true;            } else {                System.out.print("第二次注册 不成功");                n++;            }        } catch (IOException e) {            System.out.print("第二次注册 不成功，出现异常");            e.printStackTrace();            n++;        }        // 第三次        try {            int _ret = depositExecuteService.regToBank(pi.getId());            if (_ret == 1) {                System.out.print("第三次注册成功!");                return true;            } else {                System.out.print("第三次注册 不成功");                n++;            }        } catch (IOException e) {            System.out.print("第三次注册 不成功，出现异常");            e.printStackTrace();            n++;        }        if (n >= 3) {            // 发布三次未注册上的消息给系统管理 员            this.notifyService.savePostBankFallNotify(pi);            return false;        }        return false;    }   /**     *退还履约保证金上传附件页面     *     * @param projectId     * @return     */    @RequestMapping("/finance/returnExecutePage")    public ModelAndView returnExecutePage(String projectId) {        ModelAndView mv = new ModelAndView("/auction/finance/execute-deposit-file");        AuctionInfo project = auctionService.get(AuctionInfo.class, projectId);        DepositReturn d = depositReturnService.getExcuteDeposit(projectId, Constant.DEPOSIT_TYPE_EXECUTE);        Date now =new Date();        d.setIsBid(true); // 设置已投标        mv.addObject("executeDeposit", d);        mv.addObject("project",project);        mv.addObject("now",now);        return mv;    }      /**     * @description 项目流标后显示完成保证金操作     * @author shy     * @date 2016年10月28日     */    private boolean flowStatusDepositButton(Integer status) {        List<Integer> list = new ArrayList<Integer>();        list.addAll(Arrays.asList(                Integer.valueOf(ProjectStatusAuction.FLOW.toString()),//	流标                Integer.valueOf(ProjectStatusAuction.TERMINAL.toString()),//	撤销                Integer.valueOf(ProjectStatusAuction.FLOW_SHOW.toString())	//流标公示中        ));        return list.contains(status);    }}